using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Terra.Data.Entities;

namespace Terra.Data.Entities.Identity
{
    /// <summary>
    /// 菜单实体
    /// </summary>
    [Table("Menus")]
    [Comment("菜单表")]
    [Index(nameof(Name), IsUnique = true, Name = "IX_Menu_Name")]
    [Index(nameof(AuthCode), Name = "IX_Menu_AuthCode")]
    [Index(nameof(ParentId), Name = "IX_Menu_ParentId")]
    public class Menu : AuditEntityBase<Guid>
    {
        /// <summary>
        /// 菜单名称
        /// </summary>
        [Required]
        [StringLength(30)]
        [Comment("菜单名称")]
        public string Name { get; set; }

        /// <summary>
        /// 父菜单ID
        /// </summary>
        [Comment("父菜单ID")]
        public Guid? ParentId { get; set; }

        /// <summary>
        /// 菜单标题（国际化键）
        /// </summary>
        [Required]
        [StringLength(100)]
        [Comment("菜单标题（国际化键）")]
        public string Title { get; set; }

        /// <summary>
        /// 菜单类型：menu-菜单，catalog-目录，button-按钮，embedded-内嵌，link-外链
        /// </summary>
        [Required]
        [StringLength(20)]
        [DefaultValue("menu")]
        [Comment("菜单类型：menu-菜单，catalog-目录，button-按钮，embedded-内嵌，link-外链")]
        public string Type { get; set; }

        /// <summary>
        /// 路由路径
        /// </summary>
        [StringLength(100)]
        [Comment("路由路径")]
        public string Path { get; set; }

        /// <summary>
        /// 激活路径
        /// </summary>
        [StringLength(100)]
        [Comment("激活路径，当不在导航菜单中显示时需要指定激活路径")]
        public string ActivePath { get; set; }

        /// <summary>
        /// 组件路径
        /// </summary>
        [StringLength(100)]
        [Comment("组件路径")]
        public string Component { get; set; }

        /// <summary>
        /// 外链地址
        /// </summary>
        [StringLength(255)]
        [Comment("外链或内嵌页面地址")]
        public string LinkSrc { get; set; }

        /// <summary>
        /// 图标
        /// </summary>
        [StringLength(50)]
        [Comment("菜单图标")]
        public string Icon { get; set; }

        /// <summary>
        /// 激活图标
        /// </summary>
        [StringLength(50)]
        [Comment("菜单激活图标")]
        public string ActiveIcon { get; set; }

        /// <summary>
        /// 权限编码
        /// </summary>
        [StringLength(100)]
        [Comment("权限标识")]
        public string AuthCode { get; set; }

        /// <summary>
        /// 菜单状态：1-启用，0-禁用
        /// </summary>
        [DefaultValue(1)]
        [Comment("菜单状态：1-启用，0-禁用")]
        public int Status { get; set; }

        /// <summary>
        /// 徽章类型：dot-圆点，normal-文本
        /// </summary>
        [StringLength(20)]
        [Comment("徽章类型：dot-圆点，normal-文本")]
        public string BadgeType { get; set; }

        /// <summary>
        /// 徽章内容
        /// </summary>
        [StringLength(30)]
        [Comment("徽章内容")]
        public string Badge { get; set; }

        /// <summary>
        /// 徽章样式
        /// </summary>
        [StringLength(50)]
        [Comment("徽章样式")]
        public string BadgeVariants { get; set; }

        /// <summary>
        /// 是否缓存标签页
        /// </summary>
        [DefaultValue(false)]
        [Comment("是否缓存标签页")]
        public bool KeepAlive { get; set; }

        /// <summary>
        /// 是否固定在标签页
        /// </summary>
        [DefaultValue(false)]
        [Comment("是否固定在标签页")]
        public bool AffixTab { get; set; }

        /// <summary>
        /// 在菜单中隐藏
        /// </summary>
        [DefaultValue(false)]
        [Comment("在菜单中隐藏")]
        public bool HideInMenu { get; set; }

        /// <summary>
        /// 隐藏子菜单
        /// </summary>
        [DefaultValue(false)]
        [Comment("隐藏子菜单")]
        public bool HideChildrenInMenu { get; set; }

        /// <summary>
        /// 在面包屑中隐藏
        /// </summary>
        [DefaultValue(false)]
        [Comment("在面包屑中隐藏")]
        public bool HideInBreadcrumb { get; set; }

        /// <summary>
        /// 在标签栏中隐藏
        /// </summary>
        [DefaultValue(false)]
        [Comment("在标签栏中隐藏")]
        public bool HideInTab { get; set; }

        /// <summary>
        /// 排序号
        /// </summary>
        [DefaultValue(0)]
        [Comment("排序号")]
        public int Sort { get; set; }

        /// <summary>
        /// 父菜单
        /// </summary>
        [ForeignKey(nameof(ParentId))]
        public Menu Parent { get; set; }

        /// <summary>
        /// 子菜单列表（非数据库字段）
        /// </summary>
        [NotMapped]
        public List<Menu> Children { get; set; } = new List<Menu>();

        /// <summary>
        /// 关联的权限
        /// </summary>
        public Permission Permission { get; set; }
    }
}
